package com.bjpowernode.service.impl;

import com.bjpowernode.constant.Constant;
import com.bjpowernode.entity.TActivityRemark;
import com.bjpowernode.mapper.TActivityRemarkMapper;
import com.bjpowernode.query.ActivityRemarkQuery;
import com.bjpowernode.service.ActivityRemarkService;
import com.bjpowernode.util.LoginInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
@RequiredArgsConstructor
public class ActivityRemarkServiceImpl implements ActivityRemarkService {

    private final TActivityRemarkMapper tActivityRemarkMapper;

    @Override
    public int saveActivityRemark(ActivityRemarkQuery activityRemarkQuery) {
        TActivityRemark tActivityRemark = new TActivityRemark();
        tActivityRemark.setActivityId(activityRemarkQuery.getActivityId());
        tActivityRemark.setNoteContent(activityRemarkQuery.getNoteContent());

        tActivityRemark.setCreateBy(LoginInfoUtil.getCurrentLoginUser().getId());
        tActivityRemark.setCreateTime(new Date());
        return tActivityRemarkMapper.insertSelective(tActivityRemark);
    }

    @Override
    public PageInfo<TActivityRemark> getActivityRemarkByPage(Integer current, Integer activityId) {
        PageHelper.startPage(current, Constant.PAGE_SIZE);
        List<TActivityRemark> tActivityRemarkList = tActivityRemarkMapper.selectByPage(activityId);
        PageInfo<TActivityRemark> pageInfo = new PageInfo<>(tActivityRemarkList);
        return pageInfo;
    }
}
